<?php
use Yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
$this->title = '顶部导航';
?>
<div class="container">
    <div class="row">

        <?php echo $this->render('_leftnav') ?>
        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">顶部导航</h1>
            <div class="pull-right">


    <button class="btn btn-success btn-sm pull-right" id="add-navigation-btn" data-toggle="modal" data-target="#addtopnav" >新增顶部导航</button>

            </div>
          </div>

            <!--新增顶部导航开始-->
            <div aria-hidden="false" style="display: none;" id="addtopnav" class="modal in"><div class="modal-dialog ">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h4 class="modal-title">新增顶部导航

                            </h4>
                        </div>
                        <div class="modal-body">
                            <?php
                            $form = ActiveForm::begin([
                                'options' => ['class' => 'form-horizontal', 'id'=>'navigation-form'],
                                'action'=>Url::to(['system/topnavadd']),
                                'method'=>'post',
                                'fieldConfig' => [
                                    'template' => '<div class="row form-group"><div class="col-md-3 control-label">{label}</div><div class="col-md-8 controls">{input}
{error}<div class="help-block"
style="display:none;"></div></div></div><p></p>'
                                ],
                            ]);
                            ?>

                            <?= $form->field($model, 'config_key')->textInput(['maxlength' => true,'class'=>'form-control']) ?>

                            <?= $form->field($model, 'nav_name')->textInput(['maxlength' => true,'class'=>'form-control']) ?>

                            <?= $form->field($model, 'nav_url')->textInput(['maxlength' => true,'class'=>'form-control']) ?>

                            <?= $form->field($model,'nav_status')->radioList(['1'=>'显示','0'=>'不显示'],['separator'=>" ","style"=>"padding-top:6px;"]); ?>

                            <div class="modal-footer">
                                <?= Html::Button('取消', ['class' => 'btn btn-link','data-dismiss'=>'modal']) ?>
                                <?= Html::submitButton('保存', ['class' => 'btn btn-primary']) ?>
                            </div>
                            <?php ActiveForm::end();?>
                        </div>
                    </div>
                </div>
            </div>
            <!--新增顶部导航结束-->
            <div id="updatenav" class="modal fade"></div>

          <?php echo $this->render('_sitesetting') ?>



<table id="navigation-table" class="table table-striped table-hover navigation-table">
	<thead>
	  <tr>
	    <th width="50%">名称</th>
	    <th width="10%">状态</th>
	    <th width="30%">操作</th>
	  </tr>
	</thead>

 	<tbody data-update-seqs-url="/admin/setting/navigation/seqs/update">
    <?php foreach($data as $k=>$v){ ?>
  	    <tr class=" has-subItems " id="navigations-tr-2" data-id="2" data-parent-id="0">
		    <td style="vertical-align: middle;">
                <span class="glyphicon glyphicon-resize-vertical"></span>
                <a href="<?=Html::encode($v['config_value']['nav_url']);?>" target="_blank"><?=Html::encode($v['config_value']['nav_name']);?></a>
            </td>
            <td>
                <?php if($v['config_value']['nav_status'] == 1) { ?>
                    开启
                <?php }else{ ?>
                    关闭
                <?php } ?>
            </td>
            <td>
                <?= Html::Button('编辑', ['class' => 'btn btn-sm btn-default edit-btn updatenav','data-target'=>'#updatenav','data-toggle'=>'modal','type'=>$v['config_id']]) ?>
                <?= Html::submitButton('删除', ['class' => 'btn btn-default delete-btn topnavdel','data-url'=>'/admin/setting/navigation/2/delete','data-target'=>'2',value=>$v['config_id']]) ?>
            </td>
        </tr>
    <?php } ?>
    </tbody>
</table>
        </div>
    </div>
</div>
<script>
    $(".updatenav").click(function(){
        var config_id=$(this).attr("type");
        $.ajax({
            type: "POST",
            url: "<?php echo  \Yii::$app->urlManager->createUrl('system/topnavupdate') ?>",
            data: "config_id="+config_id,
            success: function(msg){
                $("#updatenav").html(msg);
            }
        });
    })
    $(".topnavdel").click(function(){
        if(confirm("确定要删除此导航吗？")){
            var config_id = $(this).attr("value");
            $.ajax({
                type: "POST",
                url: "<?php echo  \Yii::$app->urlManager->createUrl('system/topnavdel') ?>",
                data: "config_id="+config_id,
                success: function(msg){
                    if(msg == 1)
                    {
                        location.reload();
                    }else if(msg == 0)
                    {
                        alert('删除失败');
                    }else
                    {
                        alert('没有传值')
                    }

                }
            });
        }
    })
</script>


